package com.mall.web.controller.business;

import com.mall.business.domain.entity.BusOrderOperateLog;
import com.mall.business.service.BusOrderOperateLogService;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 订单操作日志Controller
 *
 * @author zhonglin
 * @date 2020-05-24
 */
@Controller
@RequestMapping("/business/orderOpereateLog")
public class BusOrderOperateLogController
    extends BaseController {

  private String prefix = "business/orderOpereateLog";

  @Autowired
  private BusOrderOperateLogService busOrderOperateLogService;

  @RequiresPermissions("business:orderOpereateLog:view")
  @GetMapping()
  public String orderOpereateLog() {

    return prefix + "/orderOpereateLog";
  }

  /**
   * 查询订单操作日志列表
   */
  @RequiresPermissions("business:orderOpereateLog:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(BusOrderOperateLog busOrderOperateLog) {

    startPage();
    List<BusOrderOperateLog> list = busOrderOperateLogService.selectBusOrderOperateLogList(busOrderOperateLog);
    return getDataTable(list);
  }

  /**
   * 导出订单操作日志列表
   */
  @RequiresPermissions("business:orderOpereateLog:export")
  @Log(title = "订单操作日志", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(BusOrderOperateLog busOrderOperateLog) {

    List<BusOrderOperateLog>      list = busOrderOperateLogService.selectBusOrderOperateLogList(busOrderOperateLog);
    ExcelUtil<BusOrderOperateLog> util = new ExcelUtil<BusOrderOperateLog>(BusOrderOperateLog.class);
    return util.exportExcel(list, "orderOpereateLog");
  }

  /**
   * 新增订单操作日志
   */
  @GetMapping("/add")
  public String add() {

    return prefix + "/add";
  }

  /**
   * 新增保存订单操作日志
   */
  @RequiresPermissions("business:orderOpereateLog:add")
  @Log(title = "订单操作日志", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(BusOrderOperateLog busOrderOperateLog) {

    return toAjax(busOrderOperateLogService.insertBusOrderOperateLog(busOrderOperateLog));
  }

  /**
   * 修改订单操作日志
   */
  @GetMapping("/edit/{orderOperateLogId}")
  public String edit(@PathVariable("orderOperateLogId") Long orderOperateLogId,
                     ModelMap mmap) {

    BusOrderOperateLog busOrderOperateLog = busOrderOperateLogService.selectBusOrderOperateLogById(orderOperateLogId);
    mmap.put("busOrderOperateLog", busOrderOperateLog);
    return prefix + "/edit";
  }

  /**
   * 修改保存订单操作日志
   */
  @RequiresPermissions("business:orderOpereateLog:edit")
  @Log(title = "订单操作日志", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(BusOrderOperateLog busOrderOperateLog) {

    return toAjax(busOrderOperateLogService.updateBusOrderOperateLog(busOrderOperateLog));
  }

  /**
   * 删除订单操作日志
   */
  @RequiresPermissions("business:orderOpereateLog:remove")
  @Log(title = "订单操作日志", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(busOrderOperateLogService.deleteBusOrderOperateLogByIds(ids));
  }

}
